<template>
  <view class='common-content'>
    <!-- 右侧弹出栏 -->
    <popupForm v-model='hasPopup' :isDetail='isDetail' @submit='searchList' />
<!--    提示信息-->
    <detail-header />
    <view class="list" v-if="isDetail">
      <single-station @change='init' v-for="(item,index) in baseLister" :key="index" :pageType='pageType' :isEdit='isEdit' :item='item' :isNew='isNew' />
    </view>
    <view class="list" v-else>
      <batch v-for="(item,index) in baseLister" @change='init' :key="index" :pageType='pageType' :isEdit='isEdit' :item='item' :isNew='isNew'/>
    </view>
    <view style="width: 100%;padding: 10rpx 0;text-align: center;background-color:#00000008; color:#737373 ;margin: 15rpx 0;">---没有更多了---</view>
  </view>
</template>
<script>
import singleStation from "./components/singleStation.vue";
import detailHeader from "./components/detailHeader.vue";
import batch from "./components/batch.vue";
import popupForm from "./components/popupForm.vue";
import {getApi, postApi} from "@/inspur/utils/request";
export default {
  name: "detail2",
  data(){
    return {
      prjId: '',
      pageType: '',
      isEdit: false,
      isNew: false,
      baseLister: [],
      hasPopup: false,
      popupForm:{}
    }
  },
  onPullDownRefresh() {
    this.init()
  },
  onLoad({prjId, manageMode,isEdit=true, isNew=false, sysToken}) {
    this.prjId = prjId
    this.pageType = manageMode
    postApi('/material/api/insVa/module/getProjectFlagByPrjId',{params:{prjId}}).then(res=>{
      // 0是新项目，1是旧项目
      this.isNew = (res.data.IS_INSPECTION_VALUATION_OLD == '0')
    })
    this.isEdit = JSON.parse(isEdit)
    this.isNew = JSON.parse(isNew)
    uni.setStorageSync("sysToken", sysToken)
  },
  onShow() {
    this.init()
    // const url = window.config.env[process.env.NODE_ENV].baseUrl
    // const url = process.uniEnv.commonPMS20
    const url = window.location.origin + window.location.pathname
    let menus = [{
      ico: url+"static/imges/loudou3.png",
      callback: () => this.rightJump()
    }];
    imp.iWindow.setMenus(menus);
  },
  onHide() {
    imp.iWindow.setMenus([{
      ico: '',
      callback: () => {
          console.log('不显示')
      }
    }]);
  },
  components:{
    singleStation,
    detailHeader,
    batch,
    popupForm
  },
  computed:{
    isDetail(){
      return ['01','21', '31', '41','51'].includes(this.pageType)
    },
  },
  methods:{
    searchList(e){
      this.popupForm = e
      this.init()
    },
    init() {
      console.log(this.isDetail)
      if (this.isDetail){
        this.getDetailList();
      }else{
        this.getList()
      }
    },
    getList(){
      const data = {
        prjId:this.prjId,
        ...this.popupForm
      }
      postApi(`/material/api/insVa/app/queryValDetailsP`, {data}).then(res=>{
        this.baseLister = res.data.valuationAndPrjInfo
        // let person = res.data.valuationAndPrjInfo
        // // 列表展示根据projectProgress字段进行升序排序
        // function compare(property){
        //   return function(a,b){
        //     var value1 = a[property];
        //     var value2 = b[property];
        //     return value1 - value2;//升序,降序为value2 - value1
        //   }
        // }
        // let arr1 =person.sort(compare('projectProgress'))
        // let arr2 = arr1.filter((item) => {
        //   return item.valuationId != null
        // })
        // let arr3 = arr1.filter((item) => {
        //   return item.valuationId == null
        // })
        // this.baseLister=[...arr3, ...arr2]
      }).finally(()=>{
        uni.stopPullDownRefresh();
      })
    },
    getDetailList(){
      const params = {
        prjId:this.prjId,
        ...this.popupForm
      }
      postApi(`/material/api/insVa/app/queryValDetails`, {params}).then(res=>{
        this.baseLister = res.data.valuationInfo
        // let person = res.data.valuationInfo
        // // 列表展示根据projectProgress字段进行升序排序
        // function compare(property){
        //   return function(a,b){
        //     var value1 = a[property];
        //     var value2 = b[property];
        //     return value1 - value2;//升序,降序为value2 - value1
        //   }
        // }
        // let arr1 =person.sort(compare('projectProgress'))
        // let arr2 = arr1.filter((item) => {
        //   return item.valuationId != null
        // })
        // let arr3 = arr1.filter((item) => {
        //   return item.valuationId == null
        // })
        // this.baseLister=[...arr3, ...arr2]
      }).finally(()=>{
        uni.stopPullDownRefresh();
      })
    },
    rightJump() {
      this.hasPopup = true;
    },
  }
}
</script>

<style scoped lang='scss'>
.u-search-box {
  padding: 18rpx 30rpx;
  background-color: #FFFFFF;
  display: flex;
  border-bottom: #00000017 3rpx solid;
  .u-search-inner {
    background-color: rgb(204, 234, 234);
    width: 90%;
    border-radius: 10rpx;
    display: flex;
    align-items: center;
    padding: 10rpx 16rpx;
    background-color: white;
    border:solid 1px gray
  }
}
</style>